<template>
  <div class="address-container">
    <h2>{{ address.name }}</h2>
    <button @click="data_show">所有设备</button>
    <div v-show="show" class="device-list">
      <div class="device-box" v-for="(item, index) in device" :key="index">
        <DeviceTab :device_dtl="item"/>
      </div>
    </div>
  </div>
</template>

<script>
import request from '@/api/request';
import DeviceTab from './view_device_tab.vue';

export default {
  created() {
    // this.get_device()
  },
  props: {
    address: {
      required: true
    }
  },
  components: {
    DeviceTab
  },
  data() {
    return {
      add: {
        id: null,
        name: null
      },
      show: false,
      device: null
    }
  },
  methods: {
    data_show() {
      this.show = !this.show;
      this.get_device();
    },
    get_device() {
      this.add.id = this.address.id;
      this.add.name = this.address.name;
      request.get('http://localhost:5000/device/select?address_id=' + this.add.id).then(function (response) {
        console.log(response.data);
        this.device = response.data;
      }.bind(this));
    }
  }
}
</script>

<style scoped>
.address-container {
  width: 40%;
  padding: 20px;
  border-radius: 10px;
  border: #00bd7e 1px solid;
}

.address-container:hover {
  transform: translateY(-0.5rem);
}

h2 {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 20px;
}

button {
  padding: 10px 20px;
  font-size: 16px;
  background-color: #f0f0f0;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.device-list {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
}

.device-box {
  flex: 0 0 300px;
  margin: 10px;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background-color: #f0f0f0;
  transition: background-color 0.3s;
  cursor: pointer;
}

.device-box:hover {
  background-color: #e0e0e0;
}
</style>
